package NC66_两个链表的第一个公共结点;


class ListNode {
    int val;
    ListNode next = null;

    ListNode(int val) {
        this.val = val;
    }
}
public class Solution {
    /*
    * 1. 求长度，长的先走 两链表的长度差，接着一起走
    * 2. 两指针走完 两条链表
    * */
    public ListNode FindFirstCommonNode(ListNode pHead1, ListNode pHead2){
        ListNode p1 = pHead1;
        ListNode p2 = pHead2;
        while (p1 != p2){
            if (p1 != null){
                p1 = p1.next;

            }else {
                p1 = pHead2;
            }
            if (p2 != null){
                p2 = p2.next;
            }else {
                p2 = pHead1;
            }

        }
        return p1;
    }

}
